{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check Permutation LCCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #LCCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: CheckPermutation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判定是否互为字符重排"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给定两个由小写字母组成的字符串 <code>s1</code> 和 <code>s2</code>，请编写一个程序，确定其中一个字符串的字符重新排列后，能否变成另一个字符串。</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> <code>s1</code> = \"abc\", <code>s2</code> = \"bca\"\n",
    "<strong>输出:</strong> true \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> <code>s1</code> = \"abc\", <code>s2</code> = \"bad\"\n",
    "<strong>输出:</strong> false\n",
    "</pre>\n",
    "\n",
    "<p><strong>说明：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= len(s1) &lt;= 100 </code></li>\n",
    "\t<li><code>0 &lt;= len(s2) &lt;= 100 </code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-permutation-lcci](https://leetcode.cn/problems/check-permutation-lcci/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-permutation-lcci](https://leetcode.cn/problems/check-permutation-lcci/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"abc\"\\n\"bca\"', '\"abc\"\\n\"bad\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        return sorted(s2)==sorted(s1)        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        len_1=[0]*26\n",
    "        for i in s1:\n",
    "            len_1[ord(i)-97]+=1\n",
    "        for j in s2:\n",
    "            len_1[ord(j)-97]-=1\n",
    "        for k in len_1:\n",
    "            if not k==0:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        PachArray1 = [0]*26\n",
    "        PachArray2 = [0]*26\n",
    "        for char_s1 in s1:\n",
    "            PachArray1[ord(char_s1)-ord('a')] +=1\n",
    "        for char_s2 in s2:\n",
    "            PachArray2[ord(char_s2)-ord('a')] +=1\n",
    "        for index in range(26):\n",
    "            if PachArray1[index]!=PachArray2[index]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1) == Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        dic = defaultdict(int)\n",
    "        for i in s1:\n",
    "            dic[i]+=1\n",
    "        for j in s2:\n",
    "            dic[j]-=1\n",
    "        for k,v in dic.items():\n",
    "            if v != 0:\n",
    "                return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        res_dic = collections.defaultdict(int)\n",
    "        for i in s1:\n",
    "            res_dic[i] += 1\n",
    "        for j in s2:\n",
    "            if res_dic.get(j) is None or (res_dic.get(j) is not None and res_dic.get(j) < 1):\n",
    "                return False\n",
    "            res_dic[j] -= 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1)==Counter(s2)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1) == Counter(s2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):  return False\n",
    "        dic = {}\n",
    "        for i in s1:\n",
    "            dic[i] = dic.get(i, 0)+1\n",
    "        for i in s2:\n",
    "            if i not in dic or dic[i] == 0:    return False\n",
    "            dic[i] -= 1\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return True if sorted(s1) == sorted(s2) else False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1)==Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        dic = defaultdict(int)#初始化一个空的dict\n",
    "        for c in s1:\n",
    "            print(\"c is \",c)\n",
    "            \n",
    "            dic[c] +=1\n",
    "            print(\"dic[c]\",dic[c])\n",
    "        for c in s2:\n",
    "            dic[c]-=1\n",
    "        for val in dic.values():\n",
    "            if val!=0:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        \n",
    "        if len(s1) != len(s2): return False\n",
    "\n",
    "        d = {}\n",
    "\n",
    "        for i in range(len(s1)):\n",
    "            d[s1[i]] = d[s1[i]] + 1 if s1[i] in d else 1\n",
    "            d[s2[i]] = d[s2[i]] - 1 if s2[i] in d else -1\n",
    "        \n",
    "        for v in d.values():\n",
    "            if v != 0: return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\r\n",
    "        if (len(s1)!=len(s2)):\r\n",
    "            return False\r\n",
    "        return sorted(s1)==sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1) == Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1) == Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "# class Solution:\n",
    "#     def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "#         if len(s1) != len(s2):\n",
    "#             return False\n",
    "#         for i in s1:\n",
    "#             if i in s2:\n",
    "#                 s2 = s2.replace(i, \"\", 1)\n",
    "#         else:\n",
    "#             return s2 is \"\"\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        s1_ = sorted(s1)\n",
    "        s2_ = sorted(s2)\n",
    "\n",
    "        if s1_ == s2_:\n",
    "            return True\n",
    "        \n",
    "        else:return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "# leetcode submit region begin(Prohibit modification and deletion)\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        charmap = [0]*26\n",
    "        for ch in s1:\n",
    "            pos = ord(ch) - ord('a')\n",
    "            charmap[pos] += 1\n",
    "        for ch in s2:\n",
    "            pos = ord(ch) - ord('a')\n",
    "            charmap[pos] -= 1\n",
    "        for i in range(26):\n",
    "            if charmap[i] != 0:\n",
    "                return False\n",
    "        return True\n",
    "# leetcode submit region end(Prohibit modification and deletion)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        char_dict = {}\n",
    "        for char in s1:\n",
    "            char_dict[char] = char_dict.get(char, 0) + 1\n",
    "        \n",
    "        for char in s2:\n",
    "            char_dict[char] = char_dict.get(char, 0) - 1\n",
    "            if char_dict[char] < 0:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        a = [0] * 26\n",
    "        n1 = len(s1)\n",
    "        n2 = len(s2)\n",
    "        for i in range(n1):\n",
    "            a[ord(s1[i])-ord('a')] += 1\n",
    "        for j in range(n2):\n",
    "            a[ord(s2[j])-ord('a')] -= 1\n",
    "        for k in a:\n",
    "            if k != 0:\n",
    "                return False\n",
    "        return True\n",
    "        # return Counter(s1) == Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        \"\"\"\n",
    "        \"\"\"\n",
    "        s1Counter = Counter(s1)\n",
    "        s2Counter = Counter(s2)\n",
    "\n",
    "        if s1Counter != s2Counter:\n",
    "            return False\n",
    "        else:\n",
    "            return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!= len(s2):return False\n",
    "        if not s1 and not s2:return True\n",
    "        res = dict()\n",
    "        for i in s1:\n",
    "            if i not in res:\n",
    "                res[i] = 1\n",
    "            else:\n",
    "                res[i] +=1\n",
    "        for i in s2:\n",
    "            if i not in res:\n",
    "                return False\n",
    "            else:\n",
    "                res[i] -=1\n",
    "        for val in res.values():\n",
    "            if val != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        s1 = sorted(s1)\n",
    "        s2 = sorted(s2)\n",
    "        return s1==s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        # 1.hash表, 字符可以重排则必然字符的种类和个数是一致的\n",
    "        # 统计一个str, 然后用这个hash表减另一个str的字符，如果小于0则不满足\n",
    "        # 或者分别统计两个str的has表，比较是否一样\n",
    "        # 2. 排序str, 然后比较是否相等\n",
    "\n",
    "        s1_list = [i for i in s1]\n",
    "        s2_list = [i for i in s2]\n",
    "        s1_list.sort()\n",
    "        s2_list.sort()\n",
    "        if s1_list==s2_list:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if sorted(s1) == sorted(s2):\n",
    "            return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        ls1 = sorted(list(s1))\n",
    "        ls2 = sorted(list(s2))\n",
    "        for i in range(len(ls1)):\n",
    "            if ls1[i]!=ls2[i]:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        dic = defaultdict(int)\n",
    "        for c in s1:\n",
    "            dic[c] += 1\n",
    "        for c in s2:\n",
    "            dic[c] -= 1\n",
    "        for val in dic.values():\n",
    "            if val != 0:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return collections.Counter(s1)==collections.Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "       return Counter(s1) == Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if Counter(s1)==Counter(s2):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation1(self, s1: str, s2: str) -> bool:\n",
    "        a=dict()\n",
    "        for i in s1:\n",
    "            if i not in a:\n",
    "                a[i]=1\n",
    "            else:\n",
    "                a[i]+=1\n",
    "        for i in s2:\n",
    "            print(a)\n",
    "            if i not in a or a[i]<=0:\n",
    "                return False\n",
    "            else:\n",
    "                a[i]-=1\n",
    "\n",
    "        for k,v in a.items():\n",
    "            if v!=0:\n",
    "                return False\n",
    "        return True\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        a=dict()\n",
    "        for i in s1:\n",
    "            if i not in a:\n",
    "                a[i]=1\n",
    "            else:\n",
    "                a[i]+=1\n",
    "        b=dict()\n",
    "        for i in s2:\n",
    "            if i not in b:\n",
    "                b[i]=1\n",
    "            else:\n",
    "                b[i]+=1\n",
    "        print(a)\n",
    "        print(b)\n",
    "        print(a==b)\n",
    "        return b==a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        s1 = list(s1)\n",
    "        s2 = list(s2)\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        ls1 = sorted(list(s1))\n",
    "        ls2 = sorted(list(s2))\n",
    "        for i in range(len(ls1)):\n",
    "            if ls1[i]!=ls2[i]:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        for i in set(s1):\n",
    "            if s1.count(i) != s2.count(i):\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        # if len(s1)!=len(s2):\n",
    "        #      return False\n",
    "        # for i in s1:\n",
    "        #     if i not in s2:\n",
    "        #         return False\n",
    "        return sorted(s2)==sorted(s1)        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        \n",
    "        dic = defaultdict(int)\n",
    "        for n in s1:\n",
    "            dic[n]+=1\n",
    "        for m in s2:\n",
    "            dic[m]-=1\n",
    "        for val in dic.values():\n",
    "            if val !=0:\n",
    "                return False\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        a = [0] * 26\n",
    "        b = [0] * 26\n",
    "        for i in s1:\n",
    "            a[ord(i) - ord(\"a\")] += 1\n",
    "        for j in s2:\n",
    "            b[ord(j) - ord(\"a\")] += 1\n",
    "        if a == b: \n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1) == Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        s1, s2 = list(s1), list(s2)\n",
    "        s1.sort()\n",
    "        s2.sort()\n",
    "        return s1 == s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        li1 = sorted(list(s1))\n",
    "        li2 = sorted(list(s2))\n",
    "        if li1 == li2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        # if s1==s2:\n",
    "        #     return True\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        for c1 in s1:\n",
    "            if c1 in s2:\n",
    "                s2 = s2.replace(c1,'',1)\n",
    "            else:\n",
    "                return False   \n",
    "        if not s2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        l1=[]\n",
    "        l2=[]\n",
    "        for c1 in s1:\n",
    "            l1.append(ord(c1))\n",
    "        for c2 in s2:\n",
    "            l2.append(ord(c2))\n",
    "        l1.sort()\n",
    "        l2.sort()\n",
    "        if l1 == l2:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1) == Counter(s2)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) == 0 or len(s1) != len(s2):\n",
    "            return False\n",
    "\n",
    "        cnts = {}\n",
    "\n",
    "        for c in s1:\n",
    "            if c not in cnts:\n",
    "                cnts[c] = 0\n",
    "\n",
    "            cnts[c] += 1\n",
    "        for c in s2:\n",
    "            if c not in cnts:\n",
    "                cnts[c] = 0\n",
    "            cnts[c] -= 1\n",
    "\n",
    "        for k, v in cnts.items():\n",
    "            if v != 0:\n",
    "                return False\n",
    "\n",
    "        return True    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        di = [0]*26\n",
    "        for c1 in s1:\n",
    "            di[ord(c1)-97] += 1\n",
    "        for c2 in s2:\n",
    "            di[ord(c2)-97] -= 1\n",
    "        for num in di:\n",
    "            if num != 0:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if (len(s1) != len(s2)):\n",
    "            return False\n",
    "        dic = defaultdict(int)\n",
    "        for c in s1:\n",
    "            dic[c] += 1\n",
    "        for c in s2:\n",
    "            dic[c] -= 1\n",
    "        for var in dic.values():\n",
    "            if var != 0:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if sorted(s1)==sorted(s2):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        L1 = [0 for i in range(26)]\n",
    "        L2 = [0 for i in range(26)]\n",
    "        for i in s1:\n",
    "            L1[ord(i) - ord('a')] += 1\n",
    "        for i in s2:\n",
    "            L2[ord(i) - ord('a')] += 1\n",
    "        \n",
    "        return L1 == L2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!= len(s2):return False\n",
    "        if not s1 and not s2:return True\n",
    "        res = dict()\n",
    "        for i in s1:\n",
    "            if i not in res:\n",
    "                res[i] = 1\n",
    "            else:\n",
    "                res[i] +=1\n",
    "        for i in s2:\n",
    "            if i not in res:\n",
    "                return False\n",
    "            else:\n",
    "                res[i] -=1\n",
    "        for i in res:\n",
    "            if res[i] != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1) == Counter(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) > len(s2) or len(s1) < len(s2):\n",
    "            return False\n",
    "        else:\n",
    "            return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        c1 = Counter(s1)\n",
    "        c2 = Counter(s2)\n",
    "        return c1 == c2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return ''.join(sorted(list(s1))) == ''.join(sorted(list(s2)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        s1_l = list(s1)\n",
    "        s3 = list(s1)\n",
    "        s2 = list(s2)\n",
    "        for i in s1_l:\n",
    "            if i in s2:\n",
    "                s2.remove(i)\n",
    "                s3.remove(i)\n",
    "\n",
    "        return True if len(s2) == 0 and len(s3) == 0 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!= len(s2):return False\n",
    "        if not s1 and not s2:return True\n",
    "        res = defaultdict(int)\n",
    "        for i in s1:\n",
    "            res[i] +=1\n",
    "        for i in s2:\n",
    "            res[i] -=1\n",
    "        for val in res.values():\n",
    "            if val != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return ''.join(sorted(s1))==''.join(sorted(s2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        print(Counter(s1)) \n",
    "        \n",
    "        return Counter(s1) == Counter(s2)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return dict([(i, s1.count(i)) for i in s1]) == dict([(i, s2.count(i)) for i in s2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def CheckPermutation(self, s1: str, s2: str) -> bool:\n",
    "        return ''.join(sorted(list(s1))) == ''.join(sorted(list(s2)))"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
